package com.ai.imagetext.dto;

import com.ai.imagetext.entity.OperationLog;
import lombok.Data;

import java.time.LocalDateTime;

@Data
public class OperationLogDTO {

    private Integer id;
    private Long userId;
    private Integer type;
    private String typeDescription;
    private Long imageId;
    private Long generalId;
    private Boolean isDelete;
    private LocalDateTime createTime;

    /**
     * 从实体类转换为DTO
     */
    public static OperationLogDTO fromEntity(OperationLog operationLog) {
        if (operationLog == null) {
            return null;
        }

        OperationLogDTO dto = new OperationLogDTO();
        dto.setId(operationLog.getId());
        dto.setUserId(operationLog.getUserId());
        dto.setType(operationLog.getType());
        dto.setTypeDescription(getTypeDescription(operationLog.getType()));
        dto.setImageId(operationLog.getImageId());
        dto.setGeneralId(operationLog.getGeneralId());
        dto.setIsDelete(operationLog.getIsDelete());
        dto.setCreateTime(operationLog.getCreateTime());

        return dto;
    }

    /**
     * 从DTO转换为实体类
     */
    public static OperationLog toEntity(OperationLogDTO dto) {
        if (dto == null) {
            return null;
        }

        OperationLog entity = new OperationLog();
        entity.setId(dto.getId());
        entity.setUserId(dto.getUserId());
        entity.setType(dto.getType());
        entity.setImageId(dto.getImageId());
        entity.setGeneralId(dto.getGeneralId());
        entity.setIsDelete(dto.getIsDelete());
        entity.setCreateTime(dto.getCreateTime());

        return entity;
    }

    /**
     * 获取操作类型描述
     */
    private static String getTypeDescription(Integer type) {
        if (type == null) {
            return "未知操作";
        }

        switch (type) {
            case 0:
                return "图生文操作";
            case 1:
                return "图生图操作";
            default:
                return "未知操作";
        }
    }
}